package nevo.pkgs.newton;

import java.util.*;

import nevo.core.*;

public class NewtonOptimizer extends BaseOptimizer
{
   protected Map<String,Object> iguess;
   protected Double[] guess;
   

   public List<IRecord> getCurrentEstimates() throws Exception
   {
      return null;
   }


   public IRecord iterate(IRecord previrec) throws Exception
   {
      IRecord newrec = new IRecord();
      if (previrec == null)   newrec.setInput(iguess);
 
      double val = func.compute(newrec.getInput());
      
      //todo, compute finite-diff jacobian, hessian, solve
      
      return null;
   }

   protected Double[] getInputFromParams(Map<String, Object> params) throws Exception
   {
      if (params.size() != 1) {
         throw new Exception("[NewtonOptimizer] only accepts one argument");
      }      
      if (!params.containsKey("input")) {
         throw new Exception("[NewtonOptimizer] requires input named 'input' of type 'List<Double>'");      
      }      
      Object obj = params.get("input");
      if (!(obj instanceof Double[])) {
         throw new Exception("[NewtonOptimizer] requires input named 'input' of type 'List<Double>'");
      }
      
      return (Double[]) obj;
   }
   
   public void setInitialGuesses(List<Map<String, Object>> paramslist) throws Exception
   {  
      iguess = paramslist.get(0);
      guess = getInputFromParams(iguess);
   }
}
